﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ext.Net;
using System.Data;
using System.Text;
using System.Reflection;
using Activity;

public partial class MrjKpiDataSumRpt : ExtBaseRpt
{
    mrjapp mrj = new mrjapp();
    string mid;
    protected void Page_Load(object sender, EventArgs e)
    {
        mid = Request.Params["mid"];
        if (!X.IsAjaxRequest)
        {
            InsActLog(mid, "浏览");
            this.txtbdate.Text = DateTime.Now.ToString("yyyy-MM-01");
            this.txtedate.Text = DateTime.Now.ToString("yyyy-MM-dd");
        }
    }
    /// <summary>
    /// 查询结果
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void BtnQureyUser(object sender, DirectEventArgs e)
    {
        if (Convert.ToDateTime(txtbdate.Text) == Convert.ToDateTime("0001-01-01 00:00:00"))
        {
            ShowBox("开始日期不能为空！");
            return;
        }
        if (Convert.ToDateTime(txtedate.Text) == Convert.ToDateTime("0001-01-01 00:00:00"))
        {
            ShowBox("结束日期不能为空！");
            return;
        }
        //if (string.IsNullOrWhiteSpace(this.selectshop.Text))
        //{
        //    ShowBox("店铺不能为空！");
        //    return;
        //}
        string str = "";
        if(!string.IsNullOrWhiteSpace(this.selectshop.Text))
            str = StrSplit(this.selectshop.Text);
        var sql = string.Format("KM_MrjKpiDataSumRpt '{0}','{1}','{2}',{3},{4}",txtbdate.Text,txtedate.Text,str,this.UserId,txtType.SelectedItem.Value);
        try
        {
            this.Store1.DataSource = db.DM_GetDateSet(sql);
            this.Store1.DataBind();
        }
        catch (Exception ex)
        {
            Log.Error("每人计周月汇总报表出错！" + ex);
            ShowBox("查询出现错误！");
        }
        //QueryData(this.Store1, mid, sql);
    }
    
    /// <summary>
    /// 刷新
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void RefreshDataSet(object sender, StoreReadDataEventArgs e)
    {
        BtnQureyUser(null,null);
    }
    /// <summary>
    /// 导出
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Store1_Submit(object sender, StoreSubmitDataEventArgs e)
    {
        //导出EXCEL
        try
        {
            ExtGridToExcel(mid, "xls", e.Xml, this.Response, "每人计周月汇总表");
        }
        catch (Exception ex)
        {
            Log.Error(ex);
            ShowBox("导出出错！");
        }
    }
}
